using System;
using Rhino.Mocks;
using Xunit;

namespace Azure.Tests.Domain.ServiceFacts
{
    public class LatestPostFacts : ServiceFactBase
    {
        [Fact]
        public void LatestPostIsRetrievedFromCache()
        {
            var expect = Test.Post;
            Cache.Latest = Test.Post;

            var post = ClassUnderTest.LatestPost();

            Assert.NotNull(post);
            Assert.Equal(expect.Title, post.Title);
            Repository.AssertWasNotCalled(x => x.Last());
        }

        [Fact]
        public void LatestPostFallsBackToRepository()
        {
            var expect = Test.Post;
            Repository.Expect(x => x.Last()).Return(expect);

            var post = ClassUnderTest.LatestPost();
            
            Assert.NotNull(post);
            Assert.Equal(expect.Title, post.Title);
            Repository.VerifyAllExpectations();
        }
    }
}